<?php

namespace app\admin\service;

use app\company\service\user_profile\userArchive\basicInfo\BasicInfoService;
use app\common\Message;
use app\model\archives_model\UserArchiveModel;
use app\model\archives_model\UserArchiveTemplateModel;
use app\model\DepartmentAdminModel;
use app\model\UserModel;
use PhpOffice\PhpWord\TemplateProcessor;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Service;
use ZipArchive;

class userSeniorExportService extends Service
{
    use Message;

    public function getUserIdExport($param)
    {
        //验证身份
        $isCheck = $this->CheckParam($param);
        if(!$isCheck){
            $this->message = $this->getMessage();
            return false;
        }
        //获取要导出的信息
        $list = $this->getOrdinaryUserInfo($param);
        if(!$list){
            $this->message = $this->getMessage();
            return false;
        }
        return $this->getResult();
    }

    public function userSeniorExport($param)
    {
        //验证身份
        $isCheck = $this->CheckParam($param);
        if(!$isCheck){
            $this->message = $this->getMessage();
            return false;
        }
        //获取要导出的信息
        $list = $this->getOrdinaryUserInfo($param);
        if(!$list){
            $this->message = $this->getMessage();
            return false;
        }
        //导出excel
        $UserExportService = new UserExportService($this->app);
        $ret['excel'] = $UserExportService->UserExport($this->getResult(),$param['unit_id']);
        //导出word
        if(isset($param['type'])){
            $word = $this->ExportOrdinaryUserWord($this->getResult(),$param['type']);
            if(!$word){
                $this->message = $this->getMessage();
                return false;
            }
            $ret['word'] = $this->getResult();
        }
        $this->result = $ret;
        return true;
    }

    /**
     * 验证参数
     * @param $param
     * @return bool
     */
    public function CheckParam($param): bool
    {
        switch ($param['role_mode']){
            case 0;
                //超级管理
                break;
            case 1;
                //管理员【只能导出负责的部门】
                $departmentAdmin = new DepartmentAdminModel();
                $department_ids = $departmentAdmin->where('uid',$param['user_id'])->column('department_id');
                if(!empty($param['class_id'])){
                    foreach($param['class_id'] as $item){
                        if(!in_array($item,$department_ids)){
                            $this->message = '部门参数错误，管理员只能导出管理的部门！';
                            return false;
                        }
                    }
                }
                break;
            case 2:
            default:
                $this->message = '此账号暂无高级筛选导出权限！';
                return false;
        }
        return true;
    }

    /**
     * 获取用户ID
     * @param $param
     * @return bool
     */
    public function getOrdinaryUserInfo($param): bool
    {
        $where = [];
        if (!empty($param['role_id'])) {
            $where[] = ['role_id', '=', $param['role_id']];
        }
        if (!empty($param['start_time']) && !empty($param['end_time'])) {
            $where[] = ['time', 'between', [$param['start_time'], $param['end_time']]];
        } else {
            if (!empty($param['start_time'])) {
                $where[] = ['time', '>=', $param['start_time']];
            }
            if (!empty($param['end_time'])) {
                $where[] = ['time', '<=', $param['end_time']];
            }
        }
        if (isset($param['status']) && strlen($param['status']) > 0) {
            $where[] = ['status', '=', $param['status']];
        }
        if (isset($param['student_status']) && strlen($param['student_status']) > 0) {
            $where[] = ['student_status', 'in', $param['student_status']];
        }
        if (isset($param['sex']) && strlen($param['sex']) > 0) {
            //普通用户的性别筛选
            $UserModel = new UserModel();
            $ids = $UserModel->where('sex', '=', $param['sex'])->column('id');
            if (!empty($ids)) {
                $where[] = ['id', 'in', $ids];
            } else {
                $where[] = ['id', '=', -1];
            }
        }
        if(!empty($param['class_id'])){
            $UserModel = new UserModel();
            $ids = $UserModel->where('department_id', 'in', $param['class_id'])->column('id');
            if (count($ids)) {
                $where[] = ['id', 'in', $ids];
            } else {
                $where[] = ['id', '=', -1];
            }
        }
        if (!empty($param['department_id'])) {
            $where[] = ['department_id', 'in', $param['department_id']];
        }
        $where[] = ['role_mode', '=', 3];
        $where[] = ['unit_id','=',$param['unit_id']];
        $data = UserModel::query()->where($where)->order('id desc')->column('id');
        if(count($data)>0){
            $this->result = $data;
            return true;
        }else{
            $this->message = '暂无数据！';
            return false;
        }
    }


    /**
     * 导出
     * @param $param //要导出的用户id集合
     * @param $type //要导出的详细资料集合
     * @return bool
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function ExportOrdinaryUserWord($param, $type): bool
    {
        $zip = new ZipArchive();
        $ext = '.zip';
        $save_name = '/export/packOrdinaryUser' . date('Ym') . '/' . date('d') . '_' . time() . uniqid();
        $file_path = dirname('./public' . $save_name . $ext);
        folder_build($file_path);
        $zipFileName = $save_name . $ext; // 压缩包文件名
        if ($zip->open('./public' . $zipFileName, ZipArchive::CREATE) !== TRUE){
            $this->message = '无法创建压缩文件';
            return false;
        }
        $file = '/user_template_recode/' . date('Ym') . '/' . date('d') . '_' . time() . uniqid();
        foreach ($param as $k => $item) {
            //获取每个用户筛选的详细资料的word的文件
            $nickname  = UserModel::query()->where('id',$item)->value('name');
            $fileName = $file . $nickname . '的详细资料.docx'; //word模板名
            $this->UserInformation($item,$type,$fileName);//渲染word模板
            $zip->addFile('./public' . $fileName, $nickname . '的详细资料'.$k.'.docx');
        }
        $zip->close();
        $this->result = oss('./public' . $save_name . $ext, $ext);
        return true;
    }

    /**
     * 获取性别
     * @param $data
     * @return string
     */
    private function getSex($data): string
    {
        switch ($data['sex']){
            case 0:
                $sex = '';
                break;
            case 1:
                $sex = '男';
                break;
            default:
                $sex = '女';
                break;
        }
        return $sex;
    }

    /**
     *
     * @param $param  //要导出的用户ID合集
     * @param $type //要导出的详细资料ID合集
     * @param $fileName //模板文件的地址
     * @return bool
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function UserInformation($param, $type, $fileName): bool
    {
        //获取每个用户的内容
        $info = $this->getOrdinaryUserContent($param,$type);
        if(!$info){
            $this->message = $this->getMessage();
            return false;
        }
        $data = $this->getResult();
        $types = 0;
        if (in_array('0', $type)) $types |= 1;
        if (in_array('1', $type)) $types |= 1 << 1;
        if (in_array('2', $type)) $types |= 1 << 2;
        if (in_array('3', $type)) $types |= 1 << 3;
        if (in_array('4', $type)) $types |= 1 << 4;
        if (in_array('5', $type)) $types |= 1 << 5;
        if (in_array('6', $type)) $types |= 1 << 6;
        if (in_array('7', $type)) $types |= 1 << 7;
        //根据用户勾选的详细资料选择不同的模板
        switch ($types) {
            case 1: // 只选了基础资料【前端传值为：0】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll0.docx');
                $this->getZeroTemplate($data,$templateProcessor);
                break;
            case 3:// 选择两个：基础资料+个人自评【前端传值为：[0,1]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll0-1.docx');
                $this->getZeroTemplate($data,$templateProcessor);
                $this->getOneTemplate($data,$templateProcessor);
                break;
            case 7:// 选择两个：基础资料+个人自评+健康情况【前端传值为：[0,1,2]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll0-2.docx');
                $this->getZeroTemplate($data,$templateProcessor);
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                break;
            case 15:// 选择两个：基础资料+个人自评+健康情况+教育情况【前端传值为：[0,1,2,3]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll0-3.docx');
                $this->getZeroTemplate($data,$templateProcessor);
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                break;
            case 31:// 选择两个：基础资料+个人自评+健康情况+教育情况+残障等级【前端传值为：[0,1,2,3,4]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll0-4.docx');
                $this->getZeroTemplate($data,$templateProcessor);
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                break;
            case 63:// 选择两个：基础资料+个人自评+健康情况+教育情况+残障等级+家庭情况【前端传值为：[0,1,2,3,4,5]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll0-5.docx');
                $this->getZeroTemplate($data,$templateProcessor);
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                break;
            case 127:// 选择两个：基础资料+个人自评+健康情况+教育情况+残障等级+家庭情况+家庭访谈【前端传值为：[0,1,2,3,4,5,6]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll0-6.docx');
                $this->getZeroTemplate($data,$templateProcessor);
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                break;
            case 255:// 选择两个：基础资料+个人自评+健康情况+教育情况+残障等级+家庭情况+家庭访谈+精神状态【前端传值为：[0,1,2,3,4,5,6,7]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll0-7.docx');
                $this->getZeroTemplate($data,$templateProcessor);
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                $this->getSevenTemplate($data,$templateProcessor);
                break;
            case 2: // 只选了个人自评【前端传值为：1】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll1.docx');
                $this->getOneTemplate($data,$templateProcessor);
                break;
            case 6: // 只选了个人自评+健康情况【前端传值为：[1,2]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll1-2.docx');
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                break;
            case 14: // 只选了个人自评+健康情况+教育情况【前端传值为：[1,2,3]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll1-3.docx');
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                break;
            case 30: // 只选了个人自评+健康情况+教育情况+残障等级【前端传值为：[1,2,3,4]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll1-4.docx');
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                break;
            case 62: // 只选了个人自评+健康情况+教育情况+残障等级+家庭情况【前端传值为：[1,2,3,4,5]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll1-5.docx');
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                break;
            case 126: // 只选了个人自评+健康情况+教育情况+残障等级+家庭情况+家庭访谈【前端传值为：[1,2,3,4,5,6]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll1-6.docx');
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                break;
            case 254: // 只选了个人自评+健康情况+教育情况+残障等级+家庭情况+家庭访谈+精神状态【前端传值为：[1,2,3,4,5,6,7]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll1-7.docx');
                $this->getOneTemplate($data,$templateProcessor);
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                $this->getSevenTemplate($data,$templateProcessor);
                break;
            case 4: // 只选了健康情况【前端传值为：2】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll2.docx');
                $this->getTwoTemplate($data,$templateProcessor);
                break;
            case 12: // 只选了健康情况+教育情况【前端传值为：[2,3]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll2-3.docx');
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                break;
            case 28: // 只选了健康情况+教育情况+残障等级【前端传值为：[2,3,4]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll2-4.docx');
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                break;
            case 60: // 只选了健康情况+教育情况+残障等级+家庭情况【前端传值为：[2,3,4,5]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll2-5.docx');
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                break;
            case 124: // 只选了健康情况+教育情况+残障等级+家庭情况+家庭访谈【前端传值为：[2,3,4,5,6]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll2-6.docx');
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                break;
            case 252: // 只选了健康情况+教育情况+残障等级+家庭情况+家庭访谈+精神状态【前端传值为：[2,3,4,5,6,7]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll2-7.docx');
                $this->getTwoTemplate($data,$templateProcessor);
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                $this->getSevenTemplate($data,$templateProcessor);
                break;
            case 8: // 只选了教育情况【前端传值为：3】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll3.docx');
                $this->getThreeTemplate($data,$templateProcessor);
                break;
            case 24: // 只选了教育情况+残障等级【前端传值为：[3,4]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll3-4.docx');
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                break;
            case 56: // 只选了教育情况+残障等级+家庭情况【前端传值为：[3,4,5]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll3-5.docx');
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                break;
            case 120: // 只选了教育情况+残障等级+家庭情况+家庭访谈【前端传值为：[3,4,5,6]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll3-6.docx');
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                break;
            case 248: // 只选了教育情况+残障等级+家庭情况+家庭访谈+精神状态【前端传值为：[3,4,5,6,7]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll3-7.docx');
                $this->getThreeTemplate($data,$templateProcessor);
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                $this->getSevenTemplate($data,$templateProcessor);
                break;
            case 16: // 只选了残障等级【前端传值为：4】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll4.docx');
                $this->getFourTemplate($data,$templateProcessor);
                break;
            case 48: // 只选了残障等级+家庭情况【前端传值为：[4,5]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll4-5.docx');
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                break;
            case 112: // 只选了残障等级+家庭情况+家庭访谈【前端传值为：[4,5,6]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll4-6.docx');
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                break;
            case 240: // 只选了残障等级+家庭情况+家庭访谈+精神状态【前端传值为：[4,5,6,7]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll4-7.docx');
                $this->getFourTemplate($data,$templateProcessor);
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                $this->getSevenTemplate($data,$templateProcessor);
                break;
            case 32: // 只选了家庭情况【前端传值为：5】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll5.docx');
                $this->getFiveTemplate($data,$templateProcessor);
                break;
            case 96: // 只选了家庭情况+家庭访谈【前端传值为：[5,6]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll5-6.docx');
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                break;
            case 224: // 只选了家庭情况+家庭访谈+精神状态【前端传值为：[5,6,7]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll5-7.docx');
                $this->getFiveTemplate($data,$templateProcessor);
                $this->getSixTemplate($data,$templateProcessor);
                $this->getSevenTemplate($data,$templateProcessor);
                break;
            case 64: // 只选了家庭访谈【前端传值为：6】
                break;
            case 192: // 只选了家庭访谈+精神状态【前端传值为：[6,7]】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll6-7.docx');
                $this->getSixTemplate($data,$templateProcessor);
                $this->getSevenTemplate($data,$templateProcessor);
                break;
            case 128: // 只选了精神状态【前端传值为：7】
                $templateProcessor = new TemplateProcessor(app()->getRootPath() . 'public/user_template/OrdinaryUserBasicAll7.docx');
                $this->getSevenTemplate($data,$templateProcessor);
                break;
        }
        // 保存修改后的文档
        $file_path  = dirname('./public' . $fileName);
        folder_build($file_path);
        $templateProcessor->saveAs('./public' . $fileName);
        return true;
    }

    /**
     * 获取基础资料的模板数据
     * @param $data
     * @param $templateProcessor
     * @return TemplateProcessor
     */
    public function getZeroTemplate($data, $templateProcessor): TemplateProcessor
    {
        $sex = $this->getSex($data['basicInfo']);
        $tempInfo = new UserService($this->app);
        $studentStatus = $tempInfo->getStudentStatusSelector();//获取所有学籍状态
        $politicalOutlook = $tempInfo->getPoliticalOutlookSelector();//获取所有政治面貌
        $nation = $tempInfo->getNationSelector();//获取所有民族
        $maritalStatus = $tempInfo->getMaritalStatusSelector();//获取所有婚姻状况

        /**基础资料-开始**/
        $templateProcessor->setValue('title', '基础资料'); // 档案标题
        if(!empty($data['basicInfo']['update_time'])){
            $update_time = $data['basicInfo']['update_time'];
        }else{
            $update_time = $data['basicInfo']['time'];
        }
        $templateProcessor->setValue('end_time', date('Y年m月d日',$update_time)); // 档案最后更新时间
        $templateProcessor->setValue('name', $data['basicInfo']['name']); // 姓名
        $templateProcessor->setValue('sex', $sex); // 性别
        $templateProcessor->setValue('age', $data['basicInfo']['age']); // 年龄
        $templateProcessor->setValue('unit_name', $data['basicInfo']['unit_name']); // 所在单位
        $templateProcessor->setValue('department', $data['basicInfo']['department_name']); // 所在部门
        $templateProcessor->setValue('number', $data['basicInfo']['student_status']); // 编号
        $templateProcessor->setValue('mode_name', $data['basicInfo']['mode_name']); // 学制类型
        $templateProcessor->setValue('rules_name', $data['basicInfo']['level_rules_name']); // 当前年级
        $templateProcessor->setValue('student', $studentStatus[$data['basicInfo']['student_status']]['value']); // 学籍状态
        $templateProcessor->setValue('id_card', $data['basicInfo']['id_card']); // 身份证号
        $templateProcessor->setValue('birthday', !empty($data['basicInfo']['birthday'])?date('Y-m-d', strtotime($data['basicInfo']['birthday'])):$data['basicInfo']['birthday']); // 出生日期
        $templateProcessor->setValue('phone', $data['basicInfo']['phone']); // 联系方式
        $templateProcessor->setValue('native_place', $data['basicInfo']['native_place']); // 籍贯
        $templateProcessor->setValue('political', $politicalOutlook[$data['basicInfo']['political_outlook']]['value']); // 政治面貌
        $templateProcessor->setValue('nation', !empty($data['basicInfo']['nation'])?$nation[$data['basicInfo']['nation']]['value']:' '); // 民族
        $templateProcessor->setValue('marital_status', $maritalStatus[$data['basicInfo']['marital_status']]['value']); // 婚姻状况
        $templateProcessor->setValue('career', $data['basicInfo']['career']); // 职业
        $templateProcessor->setValue('interest', $data['basicInfo']['interest']); // 兴趣爱好
        $templateProcessor->setValue('address', $data['basicInfo']['address']); // 详细住址

        /**基础资料-结束**/
        return $templateProcessor;
    }

    /**
     * 获取个人自评模板数据
     * @param $data
     * @param $templateProcessor
     * @return mixed
     */
    public function getOneTemplate($data, $templateProcessor): mixed
    {
        $templateProcessor->setValue('Self_info_title', '个人自评'); // 档案标题
        if(!empty($data['selfInfo'])){
            $templateProcessor->setValue('Self_info_end_time', date('Y年m月d日',$data['selfInfo']['time'])); // 档案最后更新时间
            $templateProcessor->setValue('questionSelfOne', $data['selfInfo']['self'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionSelfTwo', $data['selfInfo']['self'][1]['answer']); // 问题2
            $templateProcessor->setValue('questionSelfThree', $data['selfInfo']['self'][2]['answer']); // 问题4
            $templateProcessor->setValue('questionSelfFour', $data['selfInfo']['self'][3]['answer']); // 问题4
            $templateProcessor->setValue('questionSelfFive', $data['selfInfo']['self'][4]['answer']); // 问题5
            $templateProcessor->setValue('questionSelfSix', $data['selfInfo']['self'][5]['answer']); // 问题6
            $templateProcessor->setValue('questionSelfSeven', $data['selfInfo']['self'][6]['answer']); // 问题7
            $templateProcessor->setValue('questionSelfEight', $data['selfInfo']['self'][7]['answer']); // 问题8
            $templateProcessor->setValue('questionSelfNine', $data['selfInfo']['self'][8]['answer']); // 问题9
            $templateProcessor->setValue('questionSelfTen', $data['selfInfo']['self'][9]['answer']); // 问题10
            $templateProcessor->setValue('questionSelfEleven', $data['selfInfo']['self'][10]['answer']); // 问题11
            $templateProcessor->setValue('questionSelfTwelve', $data['selfInfo']['self'][11]['answer']); // 问题12
            $templateProcessor->setValue('questionSelfThirteen', $data['selfInfo']['self'][12]['answer']); // 问题13
            $templateProcessor->setValue('questionSelfFourteen', $data['selfInfo']['self'][13]['answer']); // 问题14
            $templateProcessor->setValue('questionSelfFifteen', $data['selfInfo']['self'][14]['answer']); // 问题15
        }else{
            $templateProcessor->setValue('Self_info_end_time', '暂无时间'); // 档案最后更新时间
            $templateProcessor->setValue('questionSelfOne', ' '); // 问题一
            $templateProcessor->setValue('questionSelfTwo', ' '); // 问题2
            $templateProcessor->setValue('questionSelfThree', ' '); // 问题4
            $templateProcessor->setValue('questionSelfFour', ' '); // 问题4
            $templateProcessor->setValue('questionSelfFive', ' '); // 问题5
            $templateProcessor->setValue('questionSelfSix', ' '); // 问题6
            $templateProcessor->setValue('questionSelfSeven', ' '); // 问题7
            $templateProcessor->setValue('questionSelfEight', ' '); // 问题8
            $templateProcessor->setValue('questionSelfNine', ' '); // 问题9
            $templateProcessor->setValue('questionSelfTen', ' '); // 问题10
            $templateProcessor->setValue('questionSelfEleven', ' '); // 问题11
            $templateProcessor->setValue('questionSelfTwelve', ' '); // 问题12
            $templateProcessor->setValue('questionSelfThirteen', ' '); // 问题13
            $templateProcessor->setValue('questionSelfFourteen', ' '); // 问题14
            $templateProcessor->setValue('questionSelfFifteen', ' '); // 问题15
        }
        return $templateProcessor;
    }

    /**
     * 获取健康情况模板数据
     * @param $data
     * @param $templateProcessor
     * @return mixed
     */
    public function getTwoTemplate($data, $templateProcessor): mixed
    {
        $templateProcessor->setValue('Health_info_title', '健康情况'); // 档案标题

        if(!empty($data['healthInfo'])){
            $templateProcessor->setValue('Health_info_end_time', date('Y年m月d日',$data['healthInfo']['time'])); // 档案最后更新时间

            /*基本健康情况-开始*/
            $templateProcessor->setValue('Developmental', $data['healthInfo']['basicHealth'][0]['answer']); // 发育状况
            $templateProcessor->setValue('weight', $data['healthInfo']['basicHealth'][1]['answer']); // 体重
            $templateProcessor->setValue('height', $data['healthInfo']['basicHealth'][2]['answer']); // 身高
            $templateProcessor->setValue('bodyType', $data['healthInfo']['basicHealth'][3]['answer']); // 身型评估
            $templateProcessor->setValue('intelligence', $data['healthInfo']['basicHealth'][4]['answer']); // 智力评估
            $templateProcessor->setValue('hearing', $data['healthInfo']['basicHealth'][5]['answer']); // 听力
            $templateProcessor->setValue('leftEyeVision', $data['healthInfo']['basicHealth'][6]['answer']); // 左眼视力
            $templateProcessor->setValue('rightEyeVision', $data['healthInfo']['basicHealth'][7]['answer']); // 右眼视力
            $templateProcessor->setValue('recognize', $data['healthInfo']['basicHealth'][8]['answer']); // 辨色能力
            $templateProcessor->setValue('language', $data['healthInfo']['basicHealth'][9]['answer']); // 语言能力
            $templateProcessor->setValue('attention', $data['healthInfo']['basicHealth'][10]['answer']); // 注意力
            $templateProcessor->setValue('disease', $data['healthInfo']['basicHealth'][11]['answer']); // 遗传病史
            $templateProcessor->setValue('eatingHabits', $data['healthInfo']['basicHealth'][12]['answer']); // 饮食习惯
            $templateProcessor->setValue('smokingSituation', $data['healthInfo']['basicHealth'][13]['answer']); // 吸烟情况
            $tempSmokingVolume = $data['healthInfo']['basicHealth'][14]['answer'];
            $templateProcessor->setValue('smokingVolume', empty($tempSmokingVolume)?$tempSmokingVolume:'日吸烟量:'.$tempSmokingVolume.'支/天'); // 日吸烟量
            $tempSmokerAge = $data['healthInfo']['basicHealth'][15]['answer'];
            $templateProcessor->setValue('smokerAge',empty($tempSmokerAge)?$tempSmokerAge:'累计烟龄:'.$tempSmokerAge.'年'); // 累计烟龄
            $tempSmokerTime = $data['healthInfo']['basicHealth'][16]['answer'];
            $templateProcessor->setValue('smokerTime', empty($tempSmokerTime)?$tempSmokerTime:'戒烟时长:'.$tempSmokerTime.'年'); // 戒烟时长
            $templateProcessor->setValue('drinkAlcohol', $data['healthInfo']['basicHealth'][17]['answer']); // 饮酒情况
            $templateProcessor->setValue('DrinkingYear', $data['healthInfo']['basicHealth'][18]['answer']); // 戒酒时长
            $templateProcessor->setValue('DrinkingFrequency', $data['healthInfo']['basicHealth'][19]['answer']); // 饮酒频率
            $templateProcessor->setValue('number', $data['healthInfo']['basicHealth'][20]['answer']); // 醉酒次数
            $templateProcessor->setValue('drunkenness', $data['healthInfo']['basicHealth'][21]['answer']); // 平均一次
            $templateProcessor->setValue('DrinkingAge', $data['healthInfo']['basicHealth'][22]['answer']); // 平均一次
            $tempDrinkType = $data['healthInfo']['basicHealth'][23]['answer'];
            $templateProcessor->setValue('drinkType', $tempDrinkType); // 饮酒种类
            if(empty($tempDrinkType)){
                $templateProcessor->setValue('drinkContent', $tempDrinkType); // 饮酒种类【其他：内容】
            }else{
                $templateProcessor->setValue('drinkContent', ''); // 饮酒种类【其他：内容】
            }
            /*基本健康情况-结束*/

            /*残疾情况-开始*/
            $templateProcessor->setValue('disability', $data['healthInfo']['disabilitySituation'][0]['answer']); // 是否残疾
            $templateProcessor->setValue('reason', $data['healthInfo']['disabilitySituation'][1]['answer']); // 残疾原因
            $templateProcessor->setValue('type', $data['healthInfo']['disabilitySituation'][2]['answer']); // 残疾分类
            $templateProcessor->setValue('level', $data['healthInfo']['disabilitySituation'][3]['answer']); // 残疾级别
            $templateProcessor->setValue('DisabilityNumber', $data['healthInfo']['disabilitySituation'][4]['answer']); // 残疾证号
            /*残疾情况-结束*/

            /*近期健康状态评估-开始*/
            $templateProcessor->setValue('health', $data['healthInfo']['recentHealth'][0]['answer']); // 健康程度
            $templateProcessor->setValue('DiagnosticResults', $data['healthInfo']['recentHealth'][1]['answer']); // 医院诊断结果
            $templateProcessor->setValue('mainSymptoms', $data['healthInfo']['recentHealth'][2]['answer']); // 主要症状
            $templateProcessor->setValue('AccompaniedSymptoms', $data['healthInfo']['recentHealth'][3]['answer']); // 伴随症状
            $templateProcessor->setValue('takeMedicine', $data['healthInfo']['recentHealth'][4]['answer']); // 是否服药
            $templateProcessor->setValue('DrugName', $data['healthInfo']['recentHealth'][5]['answer']); // 药物名称
            $templateProcessor->setValue('forbidden', $data['healthInfo']['recentHealth'][6]['answer']); // 是否忌口
            $templateProcessor->setValue('fbFoods', $data['healthInfo']['recentHealth'][7]['answer']); // 忌口食物
            $templateProcessor->setValue('fbDrug', $data['healthInfo']['recentHealth'][8]['answer']); // 忌服药物
            $templateProcessor->setValue('aberration', $data['healthInfo']['recentHealth'][9]['answer']); // 异常行为
            $templateProcessor->setValue('preference', $data['healthInfo']['recentHealth'][10]['answer']); // 特殊喜好
            $templateProcessor->setValue('hate', $data['healthInfo']['recentHealth'][11]['answer']); // 特殊厌恶
            /*近期健康状态评估-结束*/

            /*健康状况问卷-开始*/
            $templateProcessor->setValue('questionOne', $data['healthInfo']['healthQuestionnaire'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionTwo', $data['healthInfo']['healthQuestionnaire'][1]['answer']); // 问题2
            $templateProcessor->setValue('questionThree', $data['healthInfo']['healthQuestionnaire'][2]['answer']); // 问题4
            $templateProcessor->setValue('questionFour', $data['healthInfo']['healthQuestionnaire'][3]['answer']); // 问题4
            $templateProcessor->setValue('questionFive', $data['healthInfo']['healthQuestionnaire'][4]['answer']); // 问题5
            $templateProcessor->setValue('questionSix', $data['healthInfo']['healthQuestionnaire'][5]['answer']); // 问题6
            $templateProcessor->setValue('questionSeven', $data['healthInfo']['healthQuestionnaire'][6]['answer']); // 问题7
            $templateProcessor->setValue('questionEight', $data['healthInfo']['healthQuestionnaire'][7]['answer']); // 问题8
            $templateProcessor->setValue('questionNine', $data['healthInfo']['healthQuestionnaire'][8]['answer']); // 问题9
            $templateProcessor->setValue('questionTen', $data['healthInfo']['healthQuestionnaire'][9]['answer']); // 问题10
            $templateProcessor->setValue('questionEleven', $data['healthInfo']['healthQuestionnaire'][10]['answer']); // 问题11
            $templateProcessor->setValue('questionTwelve', $data['healthInfo']['healthQuestionnaire'][11]['answer']); // 问题12
            $templateProcessor->setValue('questionThirteen', $data['healthInfo']['healthQuestionnaire'][12]['answer']); // 问题13
            $templateProcessor->setValue('questionFourteen', $data['healthInfo']['healthQuestionnaire'][13]['answer']); // 问题14
            /*健康状况问卷-结束*/

        }else{
            $templateProcessor->setValue('Health_info_end_time', '暂无时间'); // 档案最后更新时间

            /*基本健康情况-开始*/
            $templateProcessor->setValue('Developmental', ' '); // 发育状况
            $templateProcessor->setValue('weight', ' '); // 体重
            $templateProcessor->setValue('height', ' '); // 身高
            $templateProcessor->setValue('bodyType', ' '); // 身型评估
            $templateProcessor->setValue('intelligence', ' '); // 智力评估
            $templateProcessor->setValue('hearing', ' '); // 听力
            $templateProcessor->setValue('leftEyeVision', ' '); // 左眼视力
            $templateProcessor->setValue('rightEyeVision', ' '); // 右眼视力
            $templateProcessor->setValue('recognize', ' '); // 辨色能力
            $templateProcessor->setValue('language', ' '); // 语言能力
            $templateProcessor->setValue('attention', ' '); // 注意力
            $templateProcessor->setValue('disease', ' '); // 遗传病史
            $templateProcessor->setValue('eatingHabits', ' '); // 饮食习惯
            $templateProcessor->setValue('smokingSituation', ' '); // 吸烟情况
            $templateProcessor->setValue('smokingVolume', ' '); // 日吸烟量
            $templateProcessor->setValue('smokerAge',' '); // 累计烟龄
            $templateProcessor->setValue('smokerTime', ' '); // 戒烟时长
            $templateProcessor->setValue('drinkAlcohol', ' '); // 饮酒情况
            $templateProcessor->setValue('DrinkingYear', ' '); // 戒酒时长
            $templateProcessor->setValue('DrinkingFrequency', ' '); // 饮酒频率
            $templateProcessor->setValue('number', ' '); // 醉酒次数
            $templateProcessor->setValue('drunkenness', ' '); // 平均一次
            $templateProcessor->setValue('DrinkingAge', ' '); // 平均一次
            $tempDrinkType = ' ';
            $templateProcessor->setValue('drinkType', $tempDrinkType); // 饮酒种类
            if(empty($tempDrinkType)){
                $templateProcessor->setValue('drinkContent', $tempDrinkType); // 饮酒种类【其他：内容】
            }else{
                $templateProcessor->setValue('drinkContent', ''); // 饮酒种类【其他：内容】
            }
            /*基本健康情况-结束*/

            /*残疾情况-开始*/
            $templateProcessor->setValue('disability', ' '); // 是否残疾
            $templateProcessor->setValue('reason', ' '); // 残疾原因
            $templateProcessor->setValue('type', ' '); // 残疾分类
            $templateProcessor->setValue('level', ' '); // 残疾级别
            $templateProcessor->setValue('DisabilityNumber', ' '); // 残疾证号
            /*残疾情况-结束*/

            /*近期健康状态评估-开始*/
            $templateProcessor->setValue('health', ' '); // 健康程度
            $templateProcessor->setValue('DiagnosticResults', ' '); // 医院诊断结果
            $templateProcessor->setValue('mainSymptoms', ' '); // 主要症状
            $templateProcessor->setValue('AccompaniedSymptoms', ' '); // 伴随症状
            $templateProcessor->setValue('takeMedicine', ' '); // 是否服药
            $templateProcessor->setValue('DrugName', ' '); // 药物名称
            $templateProcessor->setValue('forbidden', ' '); // 是否忌口
            $templateProcessor->setValue('fbFoods', ' '); // 忌口食物
            $templateProcessor->setValue('fbDrug', ' '); // 忌服药物
            $templateProcessor->setValue('aberration', ' '); // 异常行为
            $templateProcessor->setValue('preference', ' '); // 特殊喜好
            $templateProcessor->setValue('hate', ' '); // 特殊厌恶
            /*近期健康状态评估-结束*/

            /*健康状况问卷-开始*/
            $templateProcessor->setValue('questionOne', ' '); // 问题一
            $templateProcessor->setValue('questionTwo', ' '); // 问题2
            $templateProcessor->setValue('questionThree', ' '); // 问题4
            $templateProcessor->setValue('questionFour', ' '); // 问题4
            $templateProcessor->setValue('questionFive', ' '); // 问题5
            $templateProcessor->setValue('questionSix', ' '); // 问题6
            $templateProcessor->setValue('questionSeven', ' '); // 问题7
            $templateProcessor->setValue('questionEight', ' '); // 问题8
            $templateProcessor->setValue('questionNine', ' '); // 问题9
            $templateProcessor->setValue('questionTen', ' '); // 问题10
            $templateProcessor->setValue('questionEleven', ' '); // 问题11
            $templateProcessor->setValue('questionTwelve', ' '); // 问题12
            $templateProcessor->setValue('questionThirteen', ' '); // 问题13
            $templateProcessor->setValue('questionFourteen', ' '); // 问题14
            /*健康状况问卷-结束*/
        }
        return $templateProcessor;
    }

    /**
     * 获取教育情况模板数据
     * @param $data
     * @param $templateProcessor
     * @return mixed
     */
    public function getThreeTemplate($data, $templateProcessor): mixed
    {
        /**教育情况-结束**/
        $templateProcessor->setValue('education_info_title', '教育情况'); // 档案标题
        if(!empty($data['educationInfo'])){
            $templateProcessor->setValue('education_info_end_time', date('Y年m月d日',$data['educationInfo']['time'])); // 档案最后更新时间

            /*目前教育情况概况-开始*/
            $templateProcessor->setValue('qualification', $data['educationInfo']['basicEducation'][0]['answer']); // 学历程度
            $templateProcessor->setValue('enrollment', $data['educationInfo']['basicEducation'][1]['answer']); // 就读状态
            $templateProcessor->setValue('residency', $data['educationInfo']['basicEducation'][2]['answer']); // 是否住校
            $templateProcessor->setValue('startTimes', $data['educationInfo']['basicEducation'][3]['answer']); // 入学时间
            $templateProcessor->setValue('Edepartment', $data['educationInfo']['basicEducation'][4]['answer']); // 就读年级
            $templateProcessor->setValue('semester', $data['educationInfo']['basicEducation'][5]['answer']); // 学期
            $templateProcessor->setValue('headTeacher', $data['educationInfo']['basicEducation'][6]['answer']); // 班主任
            $templateProcessor->setValue('phones', $data['educationInfo']['basicEducation'][7]['answer']); // 班主任电话
            $templateProcessor->setValue('phonep', $data['educationInfo']['basicEducation'][8]['answer']); // 家长电话
            $templateProcessor->setValue('subsidy', $data['educationInfo']['basicEducation'][9]['answer']); // 两免一补
            $templateProcessor->setValue('placementType', $data['educationInfo']['basicEducation'][10]['answer']); // 安置类型
            $templateProcessor->setValue('remark', $data['educationInfo']['basicEducation'][11]['answer']); // 备注信息
            /*目前教育情况概况-结束*/
            unset($data['educationInfo']['time']);
            unset($data['educationInfo']['basicEducation']);
            $tempDate = array_values($data['educationInfo']);
            /*其他教育经历-开始*/
            $templateProcessor->cloneBlock('result_block', count($tempDate), true, true);
            foreach($tempDate as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('qualifications#' . $index, $value[0]['answer']);  //学历程度
                $templateProcessor->setValue('graduate#' . $index, $value[1]['answer']);  //是否毕业:
                $templateProcessor->setValue('residencys#' . $index, $value[2]['answer']);  //是否住校:
                $templateProcessor->setValue('startTime#' . $index, $value[3]['answer']); //入学时间
                $templateProcessor->setValue('endTime#' . $index, $value[4]['answer']); //结束时间
                $templateProcessor->setValue('isAward#' . $index, $value[5]['answer']); //是否获奖
                $templateProcessor->setValue('awardSituation#' . $index, $value[6]['answer']); //获奖情况
                $templateProcessor->setValue('otherRemark#' . $index, $value[7]['answer']); //其他备注
                $templateProcessor->setValue('blank#' . $index, ' '); //空格
            }
            /*其他教育经历-结束*/
        }else{
            $templateProcessor->setValue('education_info_end_time', '暂无时间'); // 档案最后更新时间

            /*目前教育情况概况-开始*/
            $templateProcessor->setValue('qualification', ' '); // 学历程度
            $templateProcessor->setValue('enrollment', ' '); // 就读状态
            $templateProcessor->setValue('residency', ' '); // 是否住校
            $templateProcessor->setValue('startTimes', ' '); // 入学时间
            $templateProcessor->setValue('Edepartment', ' '); // 就读年级
            $templateProcessor->setValue('semester', ' '); // 学期
            $templateProcessor->setValue('headTeacher', ' '); // 班主任
            $templateProcessor->setValue('phones', ' '); // 班主任电话
            $templateProcessor->setValue('phonep', ' '); // 家长电话
            $templateProcessor->setValue('subsidy', ' '); // 两免一补
            $templateProcessor->setValue('placementType', ' '); // 安置类型
            $templateProcessor->setValue('remark', ' '); // 备注信息
            /*目前教育情况概况-结束*/

            /*其他教育经历-开始*/
            $templateProcessor->cloneBlock('result_block', 1, true, true);
            $templateProcessor->setValue('qualifications#1', ' ');  //学历程度
            $templateProcessor->setValue('graduate#1', ' ');  //是否毕业:
            $templateProcessor->setValue('residencys#1', ' ');  //是否住校:
            $templateProcessor->setValue('startTime#1', ' '); //入学时间
            $templateProcessor->setValue('endTime#1', ' '); //结束时间
            $templateProcessor->setValue('isAward#1', ' '); //是否获奖
            $templateProcessor->setValue('awardSituation#1', ' '); //获奖情况
            $templateProcessor->setValue('otherRemark#1', ' '); //其他备注
            $templateProcessor->setValue('blank#1', ' '); //空格
            /*其他教育经历-结束*/
        }
        /**教育情况-结束**/
        return $templateProcessor;
    }

    /**
     * 获取残障等级模板数据
     * @param $data
     * @param $templateProcessor
     * @return mixed
     */
    public function getFourTemplate($data, $templateProcessor): mixed
    {
        /**残障等级-结束**/
        $templateProcessor->setValue('disability_leve_title', '残障等级'); // 档案标题

        if(!empty($data['disabilityLevelInfo'])){
            $templateProcessor->setValue('disability_leve_end_time', date('Y年m月d日',$data['disabilityLevelInfo']['time'])); // 档案最后更新时间

            $templateProcessor->cloneRow('dType', count($data['disabilityLevelInfo']['disability']));
            foreach($data['disabilityLevelInfo']['disability'] as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('dType#' . $index, $value['type']);
                $templateProcessor->setValue('dLevel#' . $index, $value['level']);
                $templateProcessor->setValue('dRemark#' . $index, $value['remark']);
            }
        }else{
            $templateProcessor->setValue('disability_leve_end_time', '暂无时间'); // 档案最后更新时间
            $templateProcessor->cloneRow('dType', 1);
            $templateProcessor->setValue('dType#1', ' ');
            $templateProcessor->setValue('dLevel#1', ' ');
            $templateProcessor->setValue('dRemark#1', ' ');
        }
        /**残障等级-结束**/
        return $templateProcessor;
    }

    /**
     * 获取家庭情况模板数据
     * @param $data
     * @param $templateProcessor
     * @return mixed
     */
    public function getFiveTemplate($data, $templateProcessor): mixed
    {
        /**家庭情况-开始**/
        $templateProcessor->setValue('family_situation_title', '家庭情况'); // 档案标题
        if(!empty($data['familySituationInfo'])){
            $templateProcessor->setValue('family_situation_end_time', date('Y年m月d日',$data['familySituationInfo']['time'])); // 档案最后更新时间
            /*家庭背景概况-开始*/
            $templateProcessor->setValue('familySituation', $data['familySituationInfo']['familyBackground'][0]['answer']); // 家庭情况
            $templateProcessor->setValue('familySize', $data['familySituationInfo']['familyBackground'][1]['answer']); // 家庭人口数
            $templateProcessor->setValue('maritalStatus', $data['familySituationInfo']['familyBackground'][2]['answer']); // 父母婚姻状况
            $templateProcessor->setValue('familyStrength', $data['familySituationInfo']['familyBackground'][3]['answer']); // 家庭经济实力
            $templateProcessor->setValue('intelligence', $data['familySituationInfo']['familyBackground'][4]['answer']); // 有无兄弟姐妹
            $templateProcessor->setValue('homeRanking', $data['familySituationInfo']['familyBackground'][5]['answer']); // 家中排行
            $templateProcessor->setValue('selfWithParents', $data['familySituationInfo']['familyBackground'][6]['answer']); // 与父母关系
            $templateProcessor->setValue('selfWithOther', $data['familySituationInfo']['familyBackground'][7]['answer']); // 与其他成员关系
            $templateProcessor->setValue('martyrsChildren', $data['familySituationInfo']['familyBackground'][8]['answer']); // 是否烈士或优抚对象子女
            $templateProcessor->setValue('detailedHomeAddress', $data['familySituationInfo']['familyBackground'][9]['answer']); // 详细家庭住址
            /*家庭背景概况-结束*/

            /*家庭主要成员-开始*/
            $templateProcessor->cloneRow('nameF', count($data['familySituationInfo']['familyMember']));
            foreach($data['familySituationInfo']['familyMember'] as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('nameF#' . $index, $value['nickname']);  //姓名
                $templateProcessor->setValue('ageF#' . $index, $value['age']);  //年龄
                $templateProcessor->setValue('kinshipF#' . $index, $value['kinship']);  //亲属关系
                $templateProcessor->setValue('careerF#' . $index, $value['career']);  //职业
                $templateProcessor->setValue('phoneF#' . $index, $value['phone']);  //联系方式
                $templateProcessor->setValue('incomeF#' . $index, $value['income']);  //收入
                $templateProcessor->setValue('degreeF#' . $index, $value['degreeOfEducation']);  //文化程度
                $templateProcessor->setValue('conditionF#' . $index, $value['healthStatus']);  //健康状况、残疾状况
                $templateProcessor->setValue('statusF#' . $index, $value['cooperation']);  //学校配合情况
            }
            /*家庭主要成员-结束*/

            /*家庭关系问卷-开始*/
            $templateProcessor->setValue('questionOneFs', $data['familySituationInfo']['familyRelationships'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionTwoFs', $data['familySituationInfo']['familyRelationships'][1]['answer']); // 问题二
            $templateProcessor->setValue('questionThreeFs', $data['familySituationInfo']['familyRelationships'][2]['answer']); // 问题三
            $templateProcessor->setValue('questionFourFs', $data['familySituationInfo']['familyRelationships'][3]['answer']); // 问题四
            /*家庭关系问卷-结束*/

            /*日常家庭生活情况-开始*/
            $templateProcessor->setValue('questionOneOneFs', $data['familySituationInfo']['dailyFamilyLife'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionOneTwoFs', $data['familySituationInfo']['dailyFamilyLife'][1]['answer']); // 问题二
            $templateProcessor->setValue('questionOneThreeFs', $data['familySituationInfo']['dailyFamilyLife'][2]['answer']); // 问题三
            $templateProcessor->setValue('questionOneFourFs', $data['familySituationInfo']['dailyFamilyLife'][3]['answer']); // 问题四
            $templateProcessor->setValue('questionOneFiveFs', $data['familySituationInfo']['dailyFamilyLife'][4]['answer']); // 问题五
            $templateProcessor->setValue('questionOneSixFs', $data['familySituationInfo']['dailyFamilyLife'][5]['answer']); // 问题六
            $templateProcessor->setValue('questionOneSevenFs', $data['familySituationInfo']['dailyFamilyLife'][6]['answer']); // 问题七
            $templateProcessor->setValue('questionOneEightFs', $data['familySituationInfo']['dailyFamilyLife'][7]['answer']); // 问题八
            /*日常家庭生活情况-结束*/
        }else{
            $templateProcessor->setValue('family_situation_end_time', '暂无数据'); // 档案最后更新时间
            /*家庭背景概况-开始*/
            $templateProcessor->setValue('familySituation', ' '); // 家庭情况
            $templateProcessor->setValue('familySize', ' '); // 家庭人口数
            $templateProcessor->setValue('maritalStatus', ' '); // 父母婚姻状况
            $templateProcessor->setValue('familyStrength', ' '); // 家庭经济实力
            $templateProcessor->setValue('intelligence', ' '); // 有无兄弟姐妹
            $templateProcessor->setValue('homeRanking', ' '); // 家中排行
            $templateProcessor->setValue('selfWithParents', ' '); // 与父母关系
            $templateProcessor->setValue('selfWithOther', ' '); // 与其他成员关系
            $templateProcessor->setValue('martyrsChildren', ' '); // 是否烈士或优抚对象子女
            $templateProcessor->setValue('detailedHomeAddress', ' '); // 详细家庭住址
            /*家庭背景概况-结束*/

            /*家庭主要成员-开始*/
            $templateProcessor->cloneRow('nameF', 1);
            $templateProcessor->setValue('nameF#1', ' ');  //姓名
            $templateProcessor->setValue('ageF#1', ' ');  //年龄
            $templateProcessor->setValue('kinshipF#1', ' ');  //亲属关系
            $templateProcessor->setValue('careerF#1', ' ');  //职业
            $templateProcessor->setValue('phoneF#1', ' ');  //联系方式
            $templateProcessor->setValue('incomeF#1', ' ');  //收入
            $templateProcessor->setValue('degreeF#1', ' ');  //文化程度
            $templateProcessor->setValue('conditionF#1', ' ');  //健康状况、残疾状况
            $templateProcessor->setValue('statusF#1', ' ');  //学校配合情况
            /*家庭主要成员-结束*/

            /*家庭关系问卷-开始*/
            $templateProcessor->setValue('questionOneFs', ' '); // 问题一
            $templateProcessor->setValue('questionTwoFs', ' '); // 问题二
            $templateProcessor->setValue('questionThreeFs', ' '); // 问题三
            $templateProcessor->setValue('questionFourFs', ' '); // 问题四
            /*家庭关系问卷-结束*/

            /*日常家庭生活情况-开始*/
            $templateProcessor->setValue('questionOneOneFs', ' '); // 问题一
            $templateProcessor->setValue('questionOneTwoFs', ' '); // 问题二
            $templateProcessor->setValue('questionOneThreeFs', ' '); // 问题三
            $templateProcessor->setValue('questionOneFourFs', ' '); // 问题四
            $templateProcessor->setValue('questionOneFiveFs', ' '); // 问题五
            $templateProcessor->setValue('questionOneSixFs', ' '); // 问题六
            $templateProcessor->setValue('questionOneSevenFs', ' '); // 问题七
            $templateProcessor->setValue('questionOneEightFs', ' '); // 问题八
            /*日常家庭生活情况-结束*/
        }
        /**家庭情况-结束**/
        return $templateProcessor;
    }

    /**
     * 获取家庭访谈模板数据
     * @param $data
     * @param $templateProcessor
     * @return mixed
     */
    public function getSixTemplate($data, $templateProcessor): mixed
    {
        /**家庭访谈-开始**/
        $templateProcessor->setValue('family_interviews_title', '家庭访谈'); // 档案标题
        if(!empty($data['familyInterviewsInfo'])){
            $templateProcessor->setValue('family_interviews_end_time', date('Y年m月d日',$data['familyInterviewsInfo']['time'])); // 档案最后更新时间

            /*经济及教育子女情况-开始*/
            $templateProcessor->setValue('questionOneOneI', $data['familyInterviewsInfo']['economyReachEducation'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionOneTwoI', $data['familyInterviewsInfo']['economyReachEducation'][1]['answer']); // 问题二
            $templateProcessor->setValue('questionOneThreeI', $data['familyInterviewsInfo']['economyReachEducation'][2]['answer']); // 问题三
            $templateProcessor->setValue('questionOneFourI', $data['familyInterviewsInfo']['economyReachEducation'][3]['answer']); // 问题四
            $templateProcessor->setValue('questionOneFiveI', $data['familyInterviewsInfo']['economyReachEducation'][4]['answer']); // 问题五
            $templateProcessor->setValue('questionOneSixI', $data['familyInterviewsInfo']['economyReachEducation'][5]['answer']); // 问题六
            $templateProcessor->setValue('questionOneSevenI', $data['familyInterviewsInfo']['economyReachEducation'][6]['answer']); // 问题七
            $templateProcessor->setValue('questionOneEightI', $data['familyInterviewsInfo']['economyReachEducation'][7]['answer']); // 问题八
            $templateProcessor->setValue('questionOneNineI', $data['familyInterviewsInfo']['economyReachEducation'][8]['answer']); // 问题九
            $templateProcessor->setValue('questionOneTentI', $data['familyInterviewsInfo']['economyReachEducation'][9]['answer']); // 问题十
            /*经济及教育子女情况-结束*/

            /*生活习惯与能力-开始*/
            $templateProcessor->setValue('dailyEating', $data['familyInterviewsInfo']['lifestyle'][0]['answer']); // 日常进食
            $templateProcessor->setValue('dressed', $data['familyInterviewsInfo']['lifestyle'][1]['answer']); // 起床穿衣:
            $templateProcessor->setValue('dailyHygiene', $data['familyInterviewsInfo']['lifestyle'][2]['answer']); // 生活盥洗:
            $templateProcessor->setValue('goToilet', $data['familyInterviewsInfo']['lifestyle'][3]['answer']); // 如厕:
            $templateProcessor->setValue('goOut', $data['familyInterviewsInfo']['lifestyle'][4]['answer']); // 外出:
            $templateProcessor->setValue('organizeItems', $data['familyInterviewsInfo']['lifestyle'][5]['answer']); // 整理物品:
            $templateProcessor->setValue('remarkI', $data['familyInterviewsInfo']['lifestyle'][6]['answer']); // 备注信息:
            /*生活习惯与能力-结束*/

            /*居住环境-开始*/
            $templateProcessor->setValue('questionOneI', $data['familyInterviewsInfo']['livingEnvironment'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionTwoI', $data['familyInterviewsInfo']['livingEnvironment'][1]['answer']); // 问题二
            $templateProcessor->setValue('questionThreeI', $data['familyInterviewsInfo']['livingEnvironment'][2]['answer']); // 问题三
            $templateProcessor->setValue('questionFourI', $data['familyInterviewsInfo']['livingEnvironment'][3]['answer']); // 问题四
            $templateProcessor->setValue('questionFiveI', $data['familyInterviewsInfo']['livingEnvironment'][4]['answer']); // 问题五
            $templateProcessor->setValue('questionSixI', $data['familyInterviewsInfo']['livingEnvironment'][5]['answer']); // 问题六
            /*居住环境-结束*/
        }
        else{
            $templateProcessor->setValue('family_interviews_end_time', '暂无时间'); // 档案最后更新时间

            /*经济及教育子女情况-开始*/
            $templateProcessor->setValue('questionOneOneI', ' '); // 问题一
            $templateProcessor->setValue('questionOneTwoI', ' '); // 问题二
            $templateProcessor->setValue('questionOneThreeI', ' '); // 问题三
            $templateProcessor->setValue('questionOneFourI', ' '); // 问题四
            $templateProcessor->setValue('questionOneFiveI', ' '); // 问题五
            $templateProcessor->setValue('questionOneSixI', ' '); // 问题六
            $templateProcessor->setValue('questionOneSevenI', ' '); // 问题七
            $templateProcessor->setValue('questionOneEightI', ' '); // 问题八
            $templateProcessor->setValue('questionOneNineI', ' '); // 问题九
            $templateProcessor->setValue('questionOneTentI', ' '); // 问题十
            /*经济及教育子女情况-结束*/

            /*生活习惯与能力-开始*/
            $templateProcessor->setValue('dailyEating', ' '); // 日常进食
            $templateProcessor->setValue('dressed', ' '); // 起床穿衣:
            $templateProcessor->setValue('dailyHygiene', ' '); // 生活盥洗:
            $templateProcessor->setValue('goToilet', ' '); // 如厕:
            $templateProcessor->setValue('goOut', ' '); // 外出:
            $templateProcessor->setValue('organizeItems', ' '); // 整理物品:
            $templateProcessor->setValue('remarkI', ' '); // 备注信息:
            /*生活习惯与能力-结束*/

            /*居住环境-开始*/
            $templateProcessor->setValue('questionOneI', ' '); // 问题一
            $templateProcessor->setValue('questionTwoI', ' '); // 问题二
            $templateProcessor->setValue('questionThreeI', ' '); // 问题三
            $templateProcessor->setValue('questionFourI', ' '); // 问题四
            $templateProcessor->setValue('questionFiveI', ' '); // 问题五
            $templateProcessor->setValue('questionSixI', ' '); // 问题六
            /*居住环境-结束*/
        }
        /**家庭访谈-结束**/
        return $templateProcessor;
    }

    /**
     * 获取精神状态模板数据
     * @param $data
     * @param $templateProcessor
     * @return mixed
     */
    public function getSevenTemplate($data, $templateProcessor): mixed
    {
        /**精神状态-开始**/
        $templateProcessor->setValue('mental_state_title', '精神状态'); // 档案标题
        if(!empty($data['mentalStateInfo'])){
            $templateProcessor->setValue('mental_state_end_time', date('Y年m月d日',$data['mentalStateInfo']['time'])); // 档案最后更新时间

            /*精神状态概况-开始*/
            $templateProcessor->setValue('mentalState', $data['mentalStateInfo']['mentalState'][0]['answer']); // 精神状态
            $templateProcessor->setValue('hypersomnia', $data['mentalStateInfo']['mentalState'][1]['answer']); // 嗜睡:
            $templateProcessor->setValue('attackBehavior', $data['mentalStateInfo']['mentalState'][2]['answer']); // 攻击行为:
            $templateProcessor->setValue('hallucination', $data['mentalStateInfo']['mentalState'][3]['answer']); // 幻觉:
            $templateProcessor->setValue('pessimistic', $data['mentalStateInfo']['mentalState'][4]['answer']); // 容易悲观::
            $templateProcessor->setValue('sleepQuality', $data['mentalStateInfo']['mentalState'][5]['answer']); // 睡眠情况:
            $templateProcessor->setValue('forgetful', $data['mentalStateInfo']['mentalState'][6]['answer']); // 丢三落四:
            $templateProcessor->setValue('temperament', $data['mentalStateInfo']['mentalState'][7]['answer']); // 喜怒无常:
            $templateProcessor->setValue('remarkMs', $data['mentalStateInfo']['mentalState'][8]['answer']); // 备注信息:
            /*精神状态概况-结束*/

            /*精神状态概况问卷-开始*/
            $templateProcessor->setValue('questionOneOneMs', $data['mentalStateInfo']['mentalStateQuestionnaire'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionOneTwoMs', $data['mentalStateInfo']['mentalStateQuestionnaire'][1]['answer']); // 问题二
            $templateProcessor->setValue('questionOneThreeMs', $data['mentalStateInfo']['mentalStateQuestionnaire'][2]['answer']); // 问题三
            $templateProcessor->setValue('questionOneFourMs', $data['mentalStateInfo']['mentalStateQuestionnaire'][3]['answer']); // 问题四
            $templateProcessor->setValue('questionOneFiveMs', $data['mentalStateInfo']['mentalStateQuestionnaire'][4]['answer']); // 问题五
            $templateProcessor->setValue('questionOneSixMs', $data['mentalStateInfo']['mentalStateQuestionnaire'][5]['answer']); // 问题六
            $templateProcessor->setValue('questionOneSevenMs', $data['mentalStateInfo']['mentalStateQuestionnaire'][6]['answer']); // 问题七
            $templateProcessor->setValue('questionOneEightMs', $data['mentalStateInfo']['mentalStateQuestionnaire'][7]['answer']); // 问题八
            $templateProcessor->setValue('questionOneNineMs', $data['mentalStateInfo']['mentalStateQuestionnaire'][8]['answer']); // 问题九
            $templateProcessor->setValue('questionOneTentMs', $data['mentalStateInfo']['mentalStateQuestionnaire'][9]['answer']); // 问题十
            /*精神状态概况问卷-结束*/
        }else{
            $templateProcessor->setValue('mental_state_end_time', '暂无时间'); // 档案最后更新时间

            /*精神状态概况-开始*/
            $templateProcessor->setValue('mentalState', ' '); // 精神状态
            $templateProcessor->setValue('hypersomnia', ' '); // 嗜睡:
            $templateProcessor->setValue('attackBehavior', ' '); // 攻击行为:
            $templateProcessor->setValue('hallucination', ' '); // 幻觉:
            $templateProcessor->setValue('pessimistic', ' '); // 容易悲观::
            $templateProcessor->setValue('sleepQuality', ' '); // 睡眠情况:
            $templateProcessor->setValue('forgetful', ' '); // 丢三落四:
            $templateProcessor->setValue('temperament', ' '); // 喜怒无常:
            $templateProcessor->setValue('remarkMs', ' '); // 备注信息:
            /*精神状态概况-结束*/

            /*精神状态概况问卷-开始*/
            $templateProcessor->setValue('questionOneOneMs', ' '); // 问题一
            $templateProcessor->setValue('questionOneTwoMs', ' '); // 问题二
            $templateProcessor->setValue('questionOneThreeMs', ' '); // 问题三
            $templateProcessor->setValue('questionOneFourMs', ' '); // 问题四
            $templateProcessor->setValue('questionOneFiveMs', ' '); // 问题五
            $templateProcessor->setValue('questionOneSixMs', ' '); // 问题六
            $templateProcessor->setValue('questionOneSevenMs', ' '); // 问题七
            $templateProcessor->setValue('questionOneEightMs', ' '); // 问题八
            $templateProcessor->setValue('questionOneNineMs', ' '); // 问题九
            $templateProcessor->setValue('questionOneTentMs', ' '); // 问题十
            /*精神状态概况问卷-结束*/
        }
        /**精神状态-结束**/
        return $templateProcessor;
    }

    /**
     * 获取详细资料信息
     * @param $param
     * @param $type
     * @return true
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getOrdinaryUserContent($param,$type): bool
    {
        $data['user_id'] = $param;
        $basicInfo = new BasicInfoService($this->app);
        foreach($type as $item){
            $data['type'] = $item;
            switch ($item){
                case 0:
                    /*获取基础信息-开始*/
                    $temp['basicInfo'] = $basicInfo->basicInfo($data);
                    /*获取基础信息-结束*/
                    break;
                case 1:
                    /*获取个人自评-开始*/
                    $selfWhere = [
                        ['user_id', '=', $param],
                        ['type_id', '=', 1],
                        ['is_repeal', '=', 0],
                    ];
                    $info = UserArchiveModel::query()->where($selfWhere)->with(['getUserInfo'])->field('id,content,type_id,time,source')
                        ->order('time desc')->findOrEmpty();
                    if (!$info->isEmpty()) {
                        $ret['time'] = $info['time'];
                        $content = json_decode($info['content'],true);
                        foreach($content as $items){
                            $items['answerId'] = $items['answersId'];
                            unset($items['answersId']);
                            $tempQuestionContent[$items['questionId']] = $items;
                        }
                        $basicHealthTemplate = new UserArchiveTemplateModel();
                        $retName = [
                            ['name'=>'self','pid'=>16,'type_id'=>1], //健康状况问卷
                        ];
                        foreach($retName as $v){
                            $rets[$v['name']] = $basicHealthTemplate->where([['pid','=',$v['pid']],['type_id','=',$v['type_id']]])->field('id,name')->select()->toArray();
                            $ret[$v['name']] = $basicInfo->getRet($rets[$v['name']],$tempQuestionContent);
                        }
                    }else{
                        $ret = [];
                    }
                    $temp['selfInfo'] = $ret;
                    /*获取个人自评-结束*/
                    break;
                case 2:
                    /*获取健康情况数据-开始*/
                    $healthInfo = $basicInfo->getHealthInfo($data);
                    if(!$healthInfo){
                        $healthInfo = [];
                    }
                    $temp['healthInfo'] = $healthInfo;
                    /*获取健康情况数据-结束*/
                    break;
                case 3:
                    /*获取教育情况-开始*/
                    $educationInfo = $basicInfo->getEducationInfo($data);
                    if(!$educationInfo){
                        $educationInfo = [];
                    }
                    $temp['educationInfo'] = $educationInfo;
                    /*获取教育情况-结束*/
                    break;
                case 4:
                    /*获取残障等级-开始*/
                    $disabilityLevelInfo = $basicInfo->getDisabilityLevelInfo($data);
                    if(!$disabilityLevelInfo){
                        $disabilityLevelInfo = [];
                    }
                    $temp['disabilityLevelInfo'] = $disabilityLevelInfo;
                    /*获取残障等级-结束*/
                    break;
                case 5:
                    /*获取家庭情况-开始*/
                    $familySituationInfo = $basicInfo->getFamilySituationInfo($data);
                    if(!$familySituationInfo){
                        $familySituationInfo = [];
                    }
                    $temp['familySituationInfo'] = $familySituationInfo;
                    /*获取家庭情况-结束*/
                    break;
                case 6:
                    /*获取家庭访谈-开始*/
                    $familyInterviewsInfo = $basicInfo->getFamilyInterviewsInfo($data);
                    if(!$familyInterviewsInfo){
                        $familyInterviewsInfo = [];
                    }
                    $temp['familyInterviewsInfo'] = $familyInterviewsInfo;
                    /*获取家庭访谈-结束*/
                    break;
                case 7:
                    /*获取精神状态-结束*/
                    $mentalStateInfo = $basicInfo->getMentalStateInfo($data);
                    if(!$mentalStateInfo){
                        $mentalStateInfo = [];
                    }
                    $temp['mentalStateInfo'] = $mentalStateInfo;
                    /*获取精神状态-结束*/
                    break;
                default:
                    $temp = [];
                    break;
            }
        }
        $this->result = $temp;
        return true;
    }
}